package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.ConsultantEvaluation;
import com.sfzy.service.ConsultantEvaluationService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("consultantEvaluation")
public class ConsultantEvaluationController {
    @Autowired
    private ConsultantEvaluationService consultantEvaluationService;
    //增
    @PostMapping
    public R addConsultantEvaluation(@RequestBody ConsultantEvaluation consultantEvaluation) {
        int i = consultantEvaluationService.addConsultantEvaluation(consultantEvaluation);
        if(i == 0) {
            return R.fail("增加失败！");
        }
        return R.ok("增加成功！");
    }
    //删
    @DeleteMapping("{id}")
    public R deleteConsultantEvaluation(@PathVariable("id") int id) {
        int i = consultantEvaluationService.deleteConsultantEvaluation(id);
        if(i == 0) {
            return R.fail("删除失败！");
        }
        return R.ok("删除成功！");
    }
    //改
    @PutMapping
    public R updateConsultantEvaluation(@RequestBody ConsultantEvaluation consultantEvaluation) {
        int i = consultantEvaluationService.updateConsultantEvaluation(consultantEvaluation);
        if(i == 0) {
            return R.fail("修改失败！");
        }
        return R.ok("修改成功！");
    }
    //根据id查
    @GetMapping("{id}")
    public R getConsultantEvaluationById(@PathVariable("id") int id) {
        ConsultantEvaluation consultantEvaluationById = consultantEvaluationService.getConsultantEvaluationById(id);
        return R.ok(consultantEvaluationById);
    }
    //分页查
    @GetMapping("page")
    public R getAllConsultantEvaluation(ConsultantEvaluation consultantEvaluation,
                                        @RequestParam(required = false,defaultValue = "1")int pageNum,
                                        @RequestParam(required = false,defaultValue = "5")int pageSize) {
        PageInfo<ConsultantEvaluation> allConsultantEvaluation = consultantEvaluationService.getAllConsultantEvaluation(consultantEvaluation, pageNum, pageSize);
        return R.ok(allConsultantEvaluation);
    }
}
